<?php 
class Controller_Client_Layout extends Controller_Template
{
	public $template = 'client';
	public $layout = 'client';
	
	public function action_index(){}

	public function before(){
		parent::before();		
		if (Request::current() === Request::initial())
		{
			$this->template->title = Lib_Setting::get('site_name');
			$this->template->keywords = Lib_Setting::get('keywords');
	        
			$this->template->main_left = array(
	                    //Request::factory('article/get_latest')->execute()
	                );
			$this->template->contents = array(
				//View::client('client')
			);
	        
	        $this->template->main_right = array(
	            View::client('land/box_search')
	        );
	        
			$this->template->partners = null;
			
			$this->set_navigator();
			 		
			$this->template->footer = View::client('footer')->set(array(
				'navigator' => Libs_Menu::getInstance()->renderFooterHtmlMenu(Libs_Menu::getInstance()->getMenuAsTree())
			));
			
			$this->template->styles = array(
				Url::client_assets().'css/style.css',
				Url::client_assets().'css/jsCarousel.css',
				Url::client_assets().'css/nivo-slider.css',
			);
			
			$this->template->scripts = array(
				Url::client_assets().'js/jquery-1.6.min.js',
				Url::client_assets().'js/jsCarousel.js',
				Url::client_assets().'js/jquery.nivo.slider.pack.js',
			);
			
		}
	}
	
	public function after(){
		parent::after();
	}
	
	public function set_navigator($navigator = null)
	{
		if(!is_null($navigator))
			$this->template->navigator = $navigator;
		else 
			$this->template->navigator = View::client('navigator')->set(array(
				'navigator' => Libs_Menu::getInstance()->renderTopHtmlMenu(Libs_Menu::getInstance()->getMenuAsTree())
			));
	}	
	
	public function set_partners($partners = null)
	{
		if(!is_null($partners)){
			$this->template->partners = $partners;
		}
	}
	
	public function set_contents($views = null)
	{
		if(is_null($views)){
			return false;
		}
		
		if(!is_array($views)){
			$views = array($views);
		}
		
		$this->template->contents = array_merge($this->template->contents,$views);
	}
	
	public function add_main_left($views = null)
	{
		if(!is_array($views)){
			$views = array($views);
		}
		$this->template->main_left = array_merge($this->template->main_left,$views);
	}
	
	public function add_main_right($views = null)
	{
		if(!is_array($views)){
			$views = array($views);
		}
		
		$this->template->main_right = array_merge($this->template->main_right,$views);
	}

	public function set_main_right($view = null)
	{
		$this->template->main_right = $view;
	}
	
	public function add_scripts($scripts)
    {
        if(!is_array($scripts))
            $scripts = array($scripts);
        $this->template->scripts = Arr::merge($this->template->scripts,$scripts);
    }

    public function add_styles($styles)
    {
        if(!is_array($styles))
            $styles = array($styles);
        $this->template->styles = Arr::merge($this->template->styles,$styles);
    }

    /**
     * gọi function này để load style và script nếu dùng uniform
     */
    public function uniform()
    {
    	$this->add_styles(array(
			Url::client_assets().'css/uni-form.css',
			Url::client_assets().'css/default.uni-form.css',
		));

		$this->add_scripts(array(
			Url::client_assets().'js/uni-form.jquery.js',
		));
    	
    }
}